package com.changhongit.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.changhongit.dao.ServiceTypeDao;
import com.changhongit.entity.ServiceType;
import com.changhongit.service.ServiceTypeService;
import com.changhongit.util.Common;
import com.changhongit.util.PageView;

@Transactional
@Service("serviceTypeService")
public class ServiceTypeServiceImpl implements ServiceTypeService {
	@Autowired
	private ServiceTypeDao serviceTypeDao;

	public PageView query(PageView pageView, ServiceType serviceType) {
		List<ServiceType> list = serviceTypeDao.query(pageView, serviceType);
		pageView.setRecords(list);
		return pageView;
	}

	public void add(ServiceType serviceType) {
		serviceTypeDao.add(serviceType);

	}

	public void delete(String id) {
		serviceTypeDao.delete(id);

	}

	public ServiceType getById(String id) {
		return serviceTypeDao.getById(id);
	}

	public void modify(ServiceType serviceType) {
		serviceTypeDao.modify(serviceType);
	}

	public List<ServiceType> findAll() {
		return serviceTypeDao.findAll();
	}

	public void saveServiceType(String id, List<String> list) {
		serviceTypeDao.deleteServiceType(id);
		for (String rId : list) {
			if (!Common.isEmpty(rId)) {
				ServiceType serviceType = new ServiceType();
				serviceType.setId(Integer.parseInt(rId));
				serviceTypeDao.saveServiceType(serviceType);
			}
		}
	}

	@Override
	public List<ServiceType> findByPid(int pid) {
		return serviceTypeDao.findByPid(pid);
	}
}
